package myky.com.doctorapp.presenter;

import io.reactivex.disposables.Disposable;
import myky.com.doctorapp.entity.VersionEntity;
import myky.com.doctorapp.base.BasePresenterIm;
import myky.com.doctorapp.base.RxSubscribe;
import myky.com.doctorapp.contract.MainActivityContract;
import myky.com.doctorapp.model.MainActivityModel;

/**
 * @author Mr.li
 */
public class MainActivityPresenter extends BasePresenterIm<MainActivityContract.View> implements MainActivityContract.Presenter {

    private MainActivityModel mainActivityModel;

    public MainActivityPresenter() {
        mainActivityModel = new MainActivityModel();
    }

    @Override
    public void checkVersion() {
        mainActivityModel.checkVersion().subscribe(new RxSubscribe<VersionEntity.PayLoadBean>() {
            @Override
            public void onSubscribe(Disposable d) {
                addSubscription(d);
                mView.showContentView();
                mView.showLoadingView();
            }

            @Override
            protected void onSuccess(VersionEntity.PayLoadBean bean) {
                mView.showContentView();
                if (bean != null){
                    mView.showVersion(bean);
                }
            }

            @Override
            protected void onFailed(int code, String msg) {
                mView.logCat(msg);
                mView.showContentView();
                mView.showRetryView();
            }

        });
    }
}
